﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QUANLIHOCSINH.BussinessObject;
using QUANLIHOCSINH.BussinessLogic;
namespace QUANLIHOCSINH
{
    enum Status_QuanLiBangDiem { View, Insert, Update, Delete };
    public partial class FrmQuanLiDiem : Form
    {
        Status_QuanLiBangDiem TrangThai = Status_QuanLiBangDiem.View;
        BANGDIEMBUS bangdiem = new BANGDIEMBUS();
        HOCKYBUS hocky = new HOCKYBUS();
        MONHOCBUS monhoc = new MONHOCBUS();
        HOCSINHBUS hocsinh = new HOCSINHBUS();
        public FrmQuanLiDiem()
        {
            InitializeComponent();
        }
        private void EnableButton(bool Enable)
        {
            
            btnSua.Visible = !Enable;
    
            btnCapNhat.Visible = Enable;
            btnHuy.Visible = Enable;
            gbbangdiem.Enabled = Enable;
        }
        private void FrmQuanLiDiem_Load(object sender, EventArgs e)
        {
            cbHocKy.DataSource = hocky.LayDanhSachHocKy();
            cbHocKy.DisplayMember = "TenHocKy";
            cbHocKy.ValueMember = "MaHocKy";

            cbMon.DataSource = monhoc.LayDanhSachMonHoc();
            cbMon.DisplayMember = "TenMon";
            cbMon.ValueMember = "MaMon";
            
            cbHocSinh.DataSource = hocsinh.LayDanhSachHocSinh();
            cbHocSinh.DisplayMember = "TenHocSinh";
            cbHocSinh.ValueMember = "MaHocSinh";

            EnableButton(false);
        }
       
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
        
            if (TrangThai == Status_QuanLiBangDiem.Update)
            {
                //MessageBox.Show(Utility.STT);
                BANGDIEM bd = new BANGDIEM();
                bd.diem_m1 = txtM1.Text;
                bd.diem_m2 = txtM2.Text;
                bd.diem_15_1 = txt15_1.Text;
                bd.diem_15_2 = txt15_2.Text;
                bd.diem_15_3 = txt15_3.Text;
                bd.diem_15_4 = txt15_4.Text;
                bd.diem_1T_1 = txt1T.Text;
                bd.diem_1T_2 = txt1T_2.Text;
                bd.diem_thi = txtDiemThi.Text;
                bd.stt = Utility.STT;
          
                bangdiem.SuaBangDiem(bd);
                dgvBangDiem.DataSource = bangdiem.LayDanhSachPhanLop("ND003", cbHocKy.SelectedValue.ToString(), cbMon.SelectedValue.ToString());
            }
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            if (dgvBangDiem.Rows.Count > 1)
            {
                int r = dgvBangDiem.CurrentRow.Index;
                cbHocSinh.SelectedValue = dgvBangDiem.Rows[r].Cells["MaHocSinh"].Value.ToString();
                txtM1.Text = dgvBangDiem.Rows[r].Cells["Diem_M1"].Value.ToString();
                txtM2.Text = dgvBangDiem.Rows[r].Cells["Diem_M2"].Value.ToString();
                txt15_1.Text = dgvBangDiem.Rows[r].Cells["Diem_15_1"].Value.ToString();
                txt15_2.Text = dgvBangDiem.Rows[r].Cells["Diem_15_2"].Value.ToString();
                txt15_3.Text = dgvBangDiem.Rows[r].Cells["Diem_15_3"].Value.ToString();
                txt15_4.Text = dgvBangDiem.Rows[r].Cells["Diem_15_4"].Value.ToString();
                txt1T.Text = dgvBangDiem.Rows[r].Cells["Diem_1T_1"].Value.ToString();
                txt1T_2.Text = dgvBangDiem.Rows[r].Cells["Diem_1T_2"].Value.ToString();
                txtDiemThi.Text = dgvBangDiem.Rows[r].Cells["Diem_Thi"].Value.ToString();
                Utility.STT = dgvBangDiem.Rows[r].Cells["STT"].Value.ToString();
            }
            EnableButton(true);
            btnSua.Visible = false;
            TrangThai = Status_QuanLiBangDiem.Update;
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {

        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            EnableButton(false);
        }

        private void btnThem_Click(object sender, EventArgs e)
        {

        }

        private void btnChon_Click(object sender, EventArgs e)
        {
            dgvBangDiem.DataSource = bangdiem.LayDanhSachPhanLop("ND003",cbHocKy.SelectedValue.ToString(),cbMon.SelectedValue.ToString() );
        }
    }
}
